/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import DataBase.Koneksi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Anggit
 */
public class KategoriBarang {

    private String idKategori;
    private String NamaKategori;
    private Connection conn;

    public KategoriBarang() {
    }

    public KategoriBarang(String idKategori, String NamaKategori) {
        this.idKategori = idKategori;
        this.NamaKategori = NamaKategori;
    }

    public String getIdKategori() {
        return idKategori;
    }

    public void setIdKategori(String idKategori) {
        this.idKategori = idKategori;
    }

    public String getNamaKategori() {
        return NamaKategori;
    }

    public void setNamaKategori(String NamaKategori) {
        this.NamaKategori = NamaKategori;
    }

    public KategoriBarang(Connection conn) {
        this.conn = conn;
    }

    public static KategoriBarang getKoneksi() throws Exception {
        KategoriBarang control;
        control = new KategoriBarang(Koneksi.open());
        return control;
    }

    public void tambahKategoriPrepared(KategoriBarang kat) throws SQLException {
        PreparedStatement stmt = null;
        try {
            conn.setAutoCommit(false);
            String query = "insert into " + "KATEGORIBARANG_FROGSTONE(kodekategori,namakategori) values (?,?)";
            stmt = conn.prepareStatement(query);
            stmt.setString(1, kat.getIdKategori());
            stmt.setString(2, kat.getNamaKategori());
            stmt.executeUpdate();
            conn.commit();
        } catch (SQLException se) {
            conn.rollback();
            throw se;
        }
    }
}
